from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-19 14:05:39.533243
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 19, Mar, 2021
Time: 14:05:43
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.9776
Nobs: 235.000 HQIC: -47.7684
Log likelihood: 2764.49 FPE: 1.05361e-21
AIC: -48.3025 Det(Omega_mle): 7.24094e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.460317 0.131526 3.500 0.000
L1.Burgenland 0.070701 0.066511 1.063 0.288
L1.Kärnten -0.206152 0.056282 -3.663 0.000
L1.Niederösterreich 0.143365 0.148640 0.965 0.335
L1.Oberösterreich 0.250799 0.134322 1.867 0.062
L1.Salzburg 0.209887 0.071907 2.919 0.004
L1.Steiermark 0.107303 0.095872 1.119 0.263
L1.Tirol 0.108040 0.064434 1.677 0.094
L1.Vorarlberg -0.000419 0.059282 -0.007 0.994
L1.Wien -0.130180 0.122859 -1.060 0.289
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.471014 0.156384 3.012 0.003
L1.Burgenland 0.018677 0.079081 0.236 0.813
L1.Kärnten 0.347434 0.066919 5.192 0.000
L1.Niederösterreich 0.089488 0.176732 0.506 0.613
L1.Oberösterreich -0.102084 0.159708 -0.639 0.523
L1.Salzburg 0.188268 0.085497 2.202 0.028
L1.Steiermark 0.190060 0.113991 1.667 0.095
L1.Tirol 0.134129 0.076611 1.751 0.080
L1.Vorarlberg 0.157292 0.070486 2.232 0.026
L1.Wien -0.481390 0.146079 -3.295 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.307562 0.061359 5.012 0.000
L1.Burgenland 0.093623 0.031029 3.017 0.003
L1.Kärnten -0.019151 0.026256 -0.729 0.466
L1.Niederösterreich 0.064705 0.069343 0.933 0.351
L1.Oberösterreich 0.297151 0.062664 4.742 0.000
L1.Salzburg 0.012965 0.033546 0.386 0.699
L1.Steiermark -0.008939 0.044726 -0.200 0.842
L1.Tirol 0.070779 0.030059 2.355 0.019
L1.Vorarlberg 0.102013 0.027656 3.689 0.000
L1.Wien 0.085634 0.057316 1.494 0.135
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.220485 0.065494 3.366 0.001
L1.Burgenland -0.000744 0.033120 -0.022 0.982
L1.Kärnten 0.014462 0.028026 0.516 0.606
L1.Niederösterreich 0.033989 0.074016 0.459 0.646
L1.Oberösterreich 0.399783 0.066886 5.977 0.000
L1.Salzburg 0.081976 0.035806 2.289 0.022
L1.Steiermark 0.172973 0.047740 3.623 0.000
L1.Tirol 0.042360 0.032085 1.320 0.187
L1.Vorarlberg 0.080267 0.029520 2.719 0.007
L1.Wien -0.045270 0.061178 -0.740 0.459
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.515325 0.129447 3.981 0.000
L1.Burgenland 0.064190 0.065460 0.981 0.327
L1.Kärnten 0.004175 0.055392 0.075 0.940
L1.Niederösterreich -0.030906 0.146291 -0.211 0.833
L1.Oberösterreich 0.148276 0.132199 1.122 0.262
L1.Salzburg 0.069756 0.070770 0.986 0.324
L1.Steiermark 0.094401 0.094356 1.000 0.317
L1.Tirol 0.222016 0.063415 3.501 0.000
L1.Vorarlberg 0.027983 0.058345 0.480 0.632
L1.Wien -0.104517 0.120917 -0.864 0.387
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186121 0.095606 1.947 0.052
L1.Burgenland -0.020792 0.048347 -0.430 0.667
L1.Kärnten -0.013325 0.040911 -0.326 0.745
L1.Niederösterreich 0.006841 0.108046 0.063 0.950
L1.Oberösterreich 0.414148 0.097638 4.242 0.000
L1.Salzburg 0.007095 0.052269 0.136 0.892
L1.Steiermark -0.018306 0.069689 -0.263 0.793
L1.Tirol 0.169325 0.046837 3.615 0.000
L1.Vorarlberg 0.050618 0.043092 1.175 0.240
L1.Wien 0.224332 0.089306 2.512 0.012
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.246551 0.123396 1.998 0.046
L1.Burgenland 0.031959 0.062400 0.512 0.609
L1.Kärnten -0.048476 0.052803 -0.918 0.359
L1.Niederösterreich -0.047116 0.139452 -0.338 0.735
L1.Oberösterreich -0.042384 0.126019 -0.336 0.737
L1.Salzburg 0.075764 0.067462 1.123 0.261
L1.Steiermark 0.359768 0.089945 4.000 0.000
L1.Tirol 0.455530 0.060451 7.536 0.000
L1.Vorarlberg 0.158915 0.055618 2.857 0.004
L1.Wien -0.186346 0.115264 -1.617 0.106
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125620 0.145043 0.866 0.386
L1.Burgenland 0.030990 0.073346 0.423 0.673
L1.Kärnten -0.059527 0.062066 -0.959 0.338
L1.Niederösterreich 0.207059 0.163916 1.263 0.207
L1.Oberösterreich -0.026538 0.148126 -0.179 0.858
L1.Salzburg 0.245998 0.079297 3.102 0.002
L1.Steiermark 0.137941 0.105724 1.305 0.192
L1.Tirol 0.041433 0.071055 0.583 0.560
L1.Vorarlberg 0.074129 0.065375 1.134 0.257
L1.Wien 0.223764 0.135485 1.652 0.099
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.579729 0.078982 7.340 0.000
L1.Burgenland -0.032987 0.039940 -0.826 0.409
L1.Kärnten -0.018104 0.033798 -0.536 0.592
L1.Niederösterreich 0.014841 0.089260 0.166 0.868
L1.Oberösterreich 0.316825 0.080661 3.928 0.000
L1.Salzburg 0.012631 0.043181 0.293 0.770
L1.Steiermark -0.017722 0.057572 -0.308 0.758
L1.Tirol 0.083105 0.038693 2.148 0.032
L1.Vorarlberg 0.114026 0.035599 3.203 0.001
L1.Wien -0.044141 0.073778 -0.598 0.550
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.134473 0.043951 0.190017 0.237054 0.066262 0.128898 -0.029432 0.162637
Kärnten 0.134473 1.000000 0.005730 0.195545 0.167653 -0.103751 0.147143 0.017475 0.305696
Niederösterreich 0.043951 0.005730 1.000000 0.267266 0.060214 0.267156 0.150889 0.050016 0.312838
Oberösterreich 0.190017 0.195545 0.267266 1.000000 0.291381 0.262069 0.096510 0.071108 0.140729
Salzburg 0.237054 0.167653 0.060214 0.291381 1.000000 0.118204 0.066146 0.087155 -0.002277
Steiermark 0.066262 -0.103751 0.267156 0.262069 0.118204 1.000000 0.123143 0.118618 -0.120824
Tirol 0.128898 0.147143 0.150889 0.096510 0.066146 0.123143 1.000000 0.167371 0.155585
Vorarlberg -0.029432 0.017475 0.050016 0.071108 0.087155 0.118618 0.167371 1.000000 0.021537
Wien 0.162637 0.305696 0.312838 0.140729 -0.002277 -0.120824 0.155585 0.021537 1.000000